<?php
namespace app\admin\controller;
use app\admin\model\login;
use think\Db;
use think\Session;
class Editpwd extends BaseController
{
    public function index()
    {
        return view();
    }
    public function editpwd(){
        $admin_id = Session::get('login_id');
        var_dump($admin_id);
        $data = [
            'oldPassword'=>input('oldPassword'),
            'newPassword'=>input('newPassword'),
            'rePassword'=>input('rePassword')
        ];
        $admin_info = Db::name("admins")->where('adminid', $admin_id)->find();
        var_dump($data);
        if ($data) {
            if ((md5($data['oldPassword'])) == $admin_info['password']) {
                if ($data['newPassword'] == $data['rePassword']) {
                    $md5_password = md5($data['newPassword']);
                    $result = Db::name("admins")->where('adminid', $admin_id)->update(['password' => $md5_password]);
                    if ($result) {
                        return $this->success('修改成功啦!');
                    } else {
                        return $this->error('修改失败');
                    }
                } else {
                    return $this->error('再次输入不一致!');
                }
            } else {
                return $this->error('原密码输入错误!');
            }
        }
    }
}